﻿//-----------------------------------------------------------------
//
// @(#)$Id: UserDetail.aspx.cs,v 1.0 2013/12/16 9:53:01 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/16 9:53:01 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_SystemTableAdapters;
using ebay.Utility;

public partial class UI_System_UserDetail : System.Web.UI.Page
{
    static string act = "";
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        //this.fdno.ReadOnly = false;                       
                        break;
                    case "U":
                        string userId = Request.QueryString["id"];
                        T_UsersTableAdapter adapter = new T_UsersTableAdapter();
                        DataTable table = adapter.GetUserByUserId(userId);
                        DataRow r = table.Rows[0];
                        this.txt_UserNo.ReadOnly = true;
                        this.txt_UserNo.Text = r["UserId"].ToString();
                        this.txt_UserName.Text = r["UserName"].ToString();
                        this.txtFitemId.Value = r["FitemId"].ToString();
                        //this.txt_PassWord.Attributes.Add("value", r["PassWord"].ToString());
                        //this.txt_OverPassWord.Attributes.Add("value", txt_PassWord.Text);
                        this.txt_Mnote.Text = r["Mnote"].ToString();
                        break;
                }
            }
        }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        string userId = Session["UserId"].ToString();
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_UsersTableAdapter adpter = new T_UsersTableAdapter();
                        int val = adpter.Insert(
                            txt_UserNo.Text,
                            txt_UserName.Text,
                            EncryptC.Md532("123"),
                            0,
                            txt_Mnote.Text,
                            userId,
                            DateTime.Now,
                            "",
                            DateTime.Now,
                            -1);

                        if (val > 0)
                        {
                            Response.Write("<script>alert('新增成功!');window.location.href='users.aspx'</script>");
                        }
                    }
                    break;
                case "U":
                    {
                        T_UsersTableAdapter adpter = new T_UsersTableAdapter();
                        int val = adpter.UpdateUserNoPass(
                            txt_UserNo.Text,
                            txt_UserName.Text,
                            0,
                            txt_Mnote.Text,
                            userId,
                            DateTime.Now,
                            "",
                            DateTime.Now,
                            Convert.ToInt32(txtFitemId.Value),
                            txt_UserNo.Text);

                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='users.aspx'</script>");
                        }
                    }
                    break;
            }
        }
    }
}